import apiUpload from '@/func/upload.js'
import { CryptoAES } from '@/utils/crypto.class.js'

export const getClient = async () => {
  const res_0 = await apiUpload.getCryptoSignKey()
  const { key, iv } = res_0.data || {}
  const res_1 = await apiUpload.getCryptoClient()
  const str = res_1.data || ''

  const cryptoAes = new CryptoAES(iv)
  let obj_str = cryptoAes.decrypt(str, key)
  
  // 过滤掉 } 后多余的字符
  const [s_0] = obj_str.split('}')
  obj_str = s_0 + '}'

  try {
    return JSON.parse(obj_str)
  } catch(e) {
    console.log('[LOG] e: ', e);
  }
}